USE [Tau]
GO

/****** Object:  StoredProcedure [dbo].[deletePage]    Script Date: 06/16/2011 22:57:30 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO




CREATE PROCEDURE [dbo].[deletePage]
@pageID int
AS

DECLARE @bolLeft bit
DECLARE @topNavID int

SELECT @bolLeft = bolLeft, @topNavID = topNavID FROM tblPages WHERE pageID = @pageID

DECLARE @orderID int
DECLARE @topOrderID int
SET @orderID = 0
SET @topOrderID = 0

--BEGIN Check for left nav
IF @bolLeft = 1
BEGIN
--Move all left nav items beneath current item back one
UPDATE tblPages SET orderID = orderID - 1 WHERE orderID > (SELECT orderID FROM tblPages WHERE pageID = @pageID)
END
--END Check for left nav

--BEGIN Check for top nav
IF @topNavID > 0
BEGIN
--Move all left nav items beneath current item back one
UPDATE tblPages SET topOrderID = topOrderID - 1 WHERE topNavID = @topNavID and topOrderID > (SELECT topOrderID FROM tblPages WHERE pageID = @pageID)
END
--END Check for top nav

DELETE FROM tblPages WHERE pageID = @pageID




GO

